package br.usp.ime.ingpos.modelo.dao;

import java.util.List;

import org.hibernate.criterion.Restrictions;

import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.ioc.RequestScoped;
import br.com.caelum.vraptor.util.hibernate.SessionCreator;
import br.usp.ime.ingpos.modelo.Bolsa;
import br.usp.ime.ingpos.modelo.IniciacaoCientifica;

@Component
@RequestScoped
public class BolsaDAO extends AbstractDaoImpl<Long, Bolsa> {

	private static final long serialVersionUID = 1L;

	public BolsaDAO(final SessionCreator sessionCreator) {
		super(sessionCreator);
	}

	public void inserirBolsa(Bolsa bolsa) {
		save(bolsa);
	}

	public void deletarBolsa(Bolsa bolsa) {
		delete(bolsa);
	}

	public void atualizarBolsa(Bolsa bolsa) {
		saveOrUpdate(bolsa);
	}

	public List<Bolsa> procurarTodasBolsas() {
		return findAll();
	}

	public Bolsa procurarBolsaById(Long bolsaId) {
		List<Bolsa> bolsas = findByCriteria(Restrictions.eq("bolsaId", bolsaId));
		if (bolsas.isEmpty()) {
			return null;
		} else {
			return bolsas.get(0);
		}
	}

}
